public class Test {

    public static void main(String[] args) {
        Container<Student> stuBox = new Container<>(new Student());
        stuBox.run();
        writeOnly(stuBox);
    }

    // super限定T类型:限定为Student以及Student的父类
    private static void writeOnly(Container<? super Student> box) {
        box.set(new Student()); // 写操作安全
        box.run();
        // Student p = box.get(); // 编译错误：不能读
    }
}

class Container<T extends Person> {
    private T instance;

    Container(T instance) {
        this.instance = instance;
    }

    void set(T t) {
        this.instance = t;
    }

    T get() {
        return instance;
    }

    void run() {
        instance.show();
    }
}

class Person {
    public void show() {
        System.out.println("Person show");
    }
}

class Student extends Person {
    @Override
    public void show() {
        System.out.println("Student show");
    }
}